package cn.appsys.service.appinfo;
import java.io.File;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import cn.appsys.dao.appinfo.DevAppMapper;
import cn.appsys.pojo.AppInfo;



@Service
public class DevAppServiceImpl implements DevAppService {
	
	@Resource
	private DevAppMapper devAppMapper;

	@Override
	public boolean add(AppInfo appInfo) throws Exception {
		boolean flag = false;
		if(devAppMapper.add(appInfo) > 0)
			flag = true;
		return flag;
	}

	@Override
	public List<AppInfo> getAppInfoList(String querySoftwareName, Integer queryStatus, Integer queryFlatformId,
			Integer queryCategoryLevel1, Integer queryCategoryLevel2, Integer queryCategoryLevel3, 
			Integer devId,Integer currentPageNo,Integer pageSize) throws Exception {
		// TODO Auto-generated method stub
		currentPageNo=(currentPageNo-1)*pageSize;
		return devAppMapper.getAppInfoList(querySoftwareName, queryStatus, queryFlatformId,
				queryCategoryLevel1, queryCategoryLevel2, queryCategoryLevel3, devId, currentPageNo, pageSize);
	}

	@Override
	public int getAppInfoCount(String querySoftwareName, Integer queryStatus, 
            Integer queryFlatfromId,
          Integer queryCategoyrLevel, Integer queryCategoyrLeve2, 
          Integer queryCategoyrLeve3, Integer queryDevId) throws Exception {
		// TODO Auto-generated method stub
		return devAppMapper.getAppInfoCount(querySoftwareName, queryStatus,queryFlatfromId,
				queryCategoyrLevel,queryCategoyrLeve2,queryCategoyrLeve3,queryDevId);
	}

	@Override
	public AppInfo getAppInfoById(Integer id) throws Exception {
		// TODO Auto-generated method stub
		return devAppMapper.getAppInfoById(id);
	}

	@Override
	public boolean deleteAppInfoById(Integer delId) throws Exception {
		// TODO Auto-generated method stub
		boolean flag = true;
		//先删除该条记录的上传附件
		AppInfo appInfo=new AppInfo();
//		appInfo = devAppMapper.deleteAppInfoById(Integer.parseInt(id));
		 appInfo = devAppMapper.getAppInfoById(delId);
		if(appInfo.getLogoLocPath() != null && !appInfo.getLogoLocPath().equals("")){
			//删除服务器上个人证件照
			File file = new File(appInfo.getLogoLocPath());
			if(file.exists()){
				flag = file.delete();
			}
		}
		if(flag && appInfo.getLogoPicPath() != null && !appInfo.getLogoPicPath().equals("")){
			//删除服务器上个人工作证照片
			File file = new File(appInfo.getLogoPicPath());
			if(file.exists()){
				flag = file.delete();
			}
		}
		if(flag){
			if(devAppMapper.deleteAppInfoById(delId) < 1)
				flag = false;
		}
		return flag;
	
	}

	@Override
	public boolean modify(AppInfo appInfo) throws Exception {
		boolean flag = false;
		if(devAppMapper.modify(appInfo) > 0)
			flag = true;
		return flag;
		
	}

	
}
